package cn.edu.hbpu.controller;

import cn.edu.hbpu.pojo.Student;
import cn.edu.hbpu.pojo.StudentCustom;
import cn.edu.hbpu.pojo.Teacher;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by yuwenteng on 2017/9/18.
 */
@Controller
@RequestMapping("user")
public class UserController {
    /**
     * @Author yuwenteng
     * @Date 2017/9/18 12:23
     * @Description 跳转主页
     */
    @RequestMapping("/home")
    public String showIndexPage() {
        return "home";
    }

    /**
     * @Author yuwenteng
     * @Date 2017/9/18 12:44
     * @Description 异步请求拿到用户信息
     */
    @RequestMapping("/getUserInfo")
    @ResponseBody
    public Object getUserInfo(HttpSession session) {
        StudentCustom studentCustom = (StudentCustom) session.getAttribute("stuInfo");
        if (studentCustom != null) {
            return studentCustom;
        } else {
            Teacher teacher = (Teacher) session.getAttribute("teaInfo");
            return teacher;
        }
    }

    /**
     * @Author yuwenteng
     * @Date 2017/9/18 20:46
     * @Description 退出系统的登录
     */
    @RequestMapping("/logout")
    public String logout(HttpSession session) {
        session.invalidate();
        return "login";
    }
}
